package com.xbts.web.controller.cloud;

import com.huaweicloud.sdk.osm.v2.model.*;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.system.domain.CnUserCases;
import com.xbts.system.service.ICloudCasesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * 云服务器工单
 * @Author llk
 * @Date 2023/8/9 14:19
 */
@RestController
@RequestMapping("/cloud/cases")
public class CloudCasesController extends BaseController {

    @Autowired
    private ICloudCasesService cloudCasesService;

    /**
     * 查询问题类型列表
     * @return 查询问题类型列表
     */
    @PostMapping("/listProblemTypes")
    public AjaxResult listProblemTypes(@RequestBody ListProblemTypesRequest listProblemTypesRequest) {
        ListProblemTypesResponse response = cloudCasesService.listProblemTypes(listProblemTypesRequest);
        if (response != null)
            return AjaxResult.success(response);
        else
            return AjaxResult.error("获取问题类型列表失败");
    }

    /**
     * 查询工单列表
     * @return 查询工单列表
     */
    @RequestMapping("/listCases")
    public AjaxResult ListCases(@RequestBody ListCasesRequest listCasesRequest) {
        return cloudCasesService.listCases(listCasesRequest);
    }

    /**
     * 本系统中用户查询工单列表
     * @return 本系统中用户查询工单列表
     */
    @PostMapping("/sysListCases")
    public AjaxResult sysListCases(@RequestBody CnUserCases cnUserCases) {
        startPage(cnUserCases);
        return success(cloudCasesService.sysListCases(cnUserCases));
    }

    /**
     * 查询某个工单状态
     * @return 查询某个工单状态
     */
    @PostMapping("/showCaseStatus")
    public AjaxResult showCaseStatus(@RequestBody ShowCaseStatusRequest showCaseStatusRequest) {
        return success(cloudCasesService.showCaseStatus(showCaseStatusRequest));
    }

    /**
     * 创建工单
     * @return 创建工单
     */
    @RequestMapping("/createCases")
    public AjaxResult createCases(@RequestBody CreateCasesRequest createCasesRequest) {
        return cloudCasesService.createCases(createCasesRequest);
    }
    /**
     * https://support.huaweicloud.com/api-ticket/ListCustomersRegions.html
     * 查询用户关联的region
     * @return 查询用户关联的region
     */
    @RequestMapping("/listCustomersRegions")
    public AjaxResult listCustomersRegions() {
        return cloudCasesService.listCustomersRegions();
    }
    /**
     * https://support.huaweicloud.com/api-ticket/ShowCaseDetail.html
     * 查询工单详情
     * @return 查询工单详情
     */
    @PostMapping("/showCaseDetail")
    public AjaxResult showCaseDetail(@RequestBody ShowCaseDetailRequest showCaseDetailRequest) {
        return cloudCasesService.showCaseDetail(showCaseDetailRequest);
    }
    /**
     * https://support.huaweicloud.com/api-ticket/UploadJsonAccessories.html
     * 上传附件
     * @return 上传附件
     */
    @PostMapping("/uploadJsonAccessories")
    public AjaxResult uploadJsonAccessories(MultipartFile file) {
        return cloudCasesService.uploadJsonAccessories(file);
    }

    /**
     * https://support.huaweicloud.com/api-ticket/CreateScores.html
     * 提交评分
     * @return 提交评分
     */
    @PostMapping("/createScores")
    public AjaxResult createScores(@RequestBody CreateScoresRequest createScoresRequest) {
        return cloudCasesService.createScores(createScoresRequest);
    }
    /**
     * https://support.huaweicloud.com/api-ticket/UpdateNewInstantMessagesRead.html
     * 设置消息已读
     * @return 设置消息已读
     */
    @PostMapping("/updateNewInstantMessagesRead")
    public AjaxResult updateNewInstantMessagesRead(@RequestBody UpdateNewInstantMessagesReadRequest updateNewInstantMessagesReadRequest) {
        return cloudCasesService.updateNewInstantMessagesRead(updateNewInstantMessagesReadRequest);
    }

    /**
     * https://support.huaweicloud.com/api-ticket/ListUnreadNewInstantMessages.html
     * 查询单个工单未读消息
     * @return 查询单个工单未读消息
     */
    @PostMapping("/listUnreadNewInstantMessages")
    public AjaxResult listUnreadNewInstantMessages(@RequestBody ListUnreadNewInstantMessagesRequest listUnreadNewInstantMessagesRequest) {
        return cloudCasesService.listUnreadNewInstantMessages(listUnreadNewInstantMessagesRequest);
    }

    /**
     * https://support.huaweicloud.com/api-ticket/CreateMessages.html
     * 提交留言
     * @return 提交留言
     */
    @PostMapping("/createMessages")
    public AjaxResult createMessages(@RequestBody CreateMessagesRequest createMessagesRequest) {
        return cloudCasesService.createMessages(createMessagesRequest);
    }

    /**
     * https://support.huaweicloud.com/api-ticket/RevokeMessage.html
     * 撤回留言
     * @return 撤回留言
     */
    @PostMapping("/revokeMessage")
    public AjaxResult revokeMessage(@RequestBody RevokeMessageRequest revokeMessageRequest) {
        return cloudCasesService.revokeMessage(revokeMessageRequest);
    }

    /**
     * https://support.huaweicloud.com/api-ticket/ListMessages.html
     * 查询留言
     * @return 查询留言
     */
    @PostMapping("/listMessages")
    public AjaxResult listMessages(@RequestBody ListMessagesRequest listMessagesRequest) {
        return cloudCasesService.listMessages(listMessagesRequest);
    }

    /**
     * https://support.huaweicloud.com/api-ticket/ListMoreInstantMessages.html
     * 查询更多留言
     * @return 查询更多留言
     */
    @PostMapping("/listMoreInstantMessages")
    public AjaxResult listMoreInstantMessages(@RequestBody ListMoreInstantMessagesRequest listMoreInstantMessagesRequest) {
        return cloudCasesService.listMoreInstantMessages(listMoreInstantMessagesRequest);
    }

    /**
     * https://support.huaweicloud.com/api-ticket/ListNewInstantMessages.html
     * 轮询查询即时消息
     * @return 轮询查询即时消息
     */
    @PostMapping("/listNewInstantMessages")
    public AjaxResult listNewInstantMessages(@RequestBody ListNewInstantMessagesRequest listNewInstantMessagesRequest) {
        return cloudCasesService.listNewInstantMessages(listNewInstantMessagesRequest);
    }

    /**
     * 获取验证码
     * @return 获取验证码
     */
    @PostMapping("/sendVerifyCodes")
    public AjaxResult sendVerifyCodes(@RequestBody SendVerifyCodesRequest sendVerifyCodesRequest) {
        return cloudCasesService.sendVerifyCodes(sendVerifyCodesRequest);
    }

    /**
     * 查询已验证的列表
     * @return 查询已验证的列表
     */
    @PostMapping("/listHasVerifiedContacts")
    public AjaxResult listHasVerifiedContacts(@RequestBody ListHasVerifiedContactsRequest listHasVerifiedContactsRequest) {
        return success(cloudCasesService.listHasVerifiedContacts(listHasVerifiedContactsRequest));
    }
    /**
     * 验证联系方式
     * @return 验证联系方式
     */
    @PostMapping("/checkVerifyCodes")
    public AjaxResult checkVerifyCodes(@RequestBody CheckVerifyCodesRequest checkVerifyCodesRequest) {
        return cloudCasesService.checkVerifyCodes(checkVerifyCodesRequest);
    }

    /**
     * 是否需要验证
     * @return 是否需要验证
     */
    @PostMapping("/checkNeedVerify")
    public AjaxResult checkNeedVerify(@RequestBody CheckNeedVerifyRequest checkNeedVerifyRequest) {
        return success(cloudCasesService.checkNeedVerify(checkNeedVerifyRequest));
    }

    /**
     * 删除附件
     * @return 删除附件
     */
    @PostMapping("/deleteAccessories")
    public AjaxResult deleteAccessories(@RequestBody DeleteAccessoriesRequest deleteAccessoriesRequest) {
        return cloudCasesService.deleteAccessories(deleteAccessoriesRequest);
    }

    /**
     * 下载附件
     * @return 下载附件
     */
    @PostMapping("/downloadAccessories")
    public void downloadAccessories(@RequestBody DownloadAccessoriesRequest downloadAccessoriesRequest, HttpServletResponse response) {
        cloudCasesService.downloadAccessories(downloadAccessoriesRequest, response);
    }

    /**
     * 图片展示
     * @return 图片展示
     */
    @PostMapping("/downloadImages")
    public void downloadImages(@RequestBody DownloadImagesRequest downloadImagesRequest, HttpServletResponse response) {
        cloudCasesService.downloadImages(downloadImagesRequest, response);
    }

    /**
     * 附件限制
     * @return 附件限制
     */
    @PostMapping("/showAccessoryLimits")
    public AjaxResult showAccessoryLimits(@RequestBody ShowAccessoryLimitsRequest showAccessoryLimitsRequest) {
        return cloudCasesService.showAccessoryLimits(showAccessoryLimitsRequest);
    }

}
